// 审批流程状态  
export enum StatusEnum {
    UnKnown = 0, // 未知的  
    Creating = 1, // 立项中
    SubmitApproval = 2, // 提交审批  
    Approvaling = 3,//审批中
    Approvald = 4,//审批结束
    ApprovePass = 5,//审批通过
    ApproveRefuse = 6,//审批不通过
    Complete = 999,//完成或结束
}

//步骤
export enum ProcessEnum {
    CreateProject,
    Requirement,
    Schedule,
    Team,
    Change,
}

// 根据值获取枚举项  
export function getStatusEnumByValue(value: number): string {
    // 遍历枚举的所有值  
    for (let key in StatusEnum) {
        if (StatusEnum[key as keyof typeof StatusEnum] === value) {
            return key;
        }
    }
    // 如果没有找到对应的枚举项，返回 undefined  
    return 'UnKnown';
}

// 根据值获取枚举项的汉字  
export function getStatusEnumChineseByValue(value: number, type: ProcessEnum): string {
    if (value == null) {
        value = 0;
    }
    const statusMap: Record<number, string> = {
        [StatusEnum.UnKnown]: getValueByType(value, type),
        [StatusEnum.Creating]: getValueByType(value, type),
        [StatusEnum.SubmitApproval]: '提交审批',
        [StatusEnum.Approvaling]: '审批中',
        [StatusEnum.Approvald]: '审批结束',
        [StatusEnum.ApprovePass]: '审批通过',
        [StatusEnum.ApproveRefuse]: '审批不通过',
    };

    return statusMap[value] || '未知的'; // 如果没有找到对应的汉字，返回 '未知的'
}

function getValueByType(value: number, type: ProcessEnum) {
    if (StatusEnum.Creating == value) {
        switch (type) {
            case ProcessEnum.Requirement:
                return '需求编制中';
            case ProcessEnum.CreateProject:
                return '立项中';
            case ProcessEnum.Schedule:
                return '计划编制中';
            case ProcessEnum.Team:
                return '组建中';
            case ProcessEnum.Change:
                return '编制中';
        }
    }
    if (StatusEnum.UnKnown == value) {
        switch (type) {
            case ProcessEnum.Requirement:
                return '未开始';
            case ProcessEnum.CreateProject:
                return '未开始';
            case ProcessEnum.Schedule:
                return '未开始';
            case ProcessEnum.Team:
                return '未组建';
            case ProcessEnum.Change:
                return '未开始';
        }
    }
}

//根据状态返回样式
export function getStatusStyle(status) {
    if (status === StatusEnum.Creating) {
        return 'status__cell underway';
    } else if (status === StatusEnum.SubmitApproval) {
        return 'status__cell aprovesubmit';
    }
    else if (status === StatusEnum.Approvaling) {
        return 'status__cell approving';
    }
    else if (status === StatusEnum.Approvald) {
        return 'status__cell finish';
    }
    else if (status === StatusEnum.ApprovePass) {
        return 'status__cell approvepass';
    }
    else if (status === StatusEnum.ApproveRefuse) {
        return 'status__cell approverefuse';
    }
    else {
        return 'status__cell unknown';
    }
}